package com.mine.controller;

import com.mine.common.pojo.BaseResult;
import com.mine.common.pojo.EasyUIDataGridResult;
import com.mine.common.pojo.EasyUITreeNode;
import com.mine.pojo.TbItem;
import com.mine.service.ItemCatService;
import com.mine.service.ItemService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Controller
@RequestMapping("/item")
public class ItemController {
    @Resource
    ItemService itemService;
    @Resource
    ItemCatService itemCatService;
    @RequestMapping("/{itemId}")
    @ResponseBody
    public TbItem getItemById(@PathVariable("itemId") Long itemId) {
        return itemService.getItemById(itemId);
    }
    @RequestMapping("/list")
    @ResponseBody
    public EasyUIDataGridResult getItemByIdList(int page, int rows) {
        return itemService.getItemByIdList(page, rows);
    }

    @RequestMapping("/cat/list")
    @ResponseBody
    public List<EasyUITreeNode> getItemCatList(@RequestParam(name = "id", defaultValue = "0") long parentId) { return itemCatService.getItemCatList(parentId); }
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public BaseResult addItem( TbItem item, String desc) {
        return itemService.addItem(item,desc);
    }



}
